﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GmInplaceEdit.h"
#include "IEditModeBehavior.h"
#include "DbDataSchema.h"
#include "IEditMode.h"


namespace gcmp
{
    class GM_INPLACE_EDIT_EXPORT InplaceEditModeBehavior : public gcmp::NdbObjectSchematic, public gcmp::IEditModeBehavior
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, InplaceEditModeBehavior, gcmp::NdbObjectSchematic, 834A04FF - 6205 - 4864 - B8E4 - D2621BCDF011, gminplaceedit, gcmp::IEditModeBehavior)
            MAP_DATA(Int64, ElementId, ProjectIdToReferenceElementIds)
            DATA(UInt16, ProjectAppPort)
        DBOBJECT_DATA_END

    public:
        static const std::wstring InplaceEditModeType;

    public:
        static gcmp::IEditMode* Create(gcmp::IDocument* pDoc);
        static bool IsInEditMode(gcmp::IDocument* pDoc);
        static const InplaceEditModeBehavior* Get(gcmp::IDocument* pDoc);
        static InplaceEditModeBehavior* GetFw(gcmp::IDocument* pDoc);

        virtual bool StartEditing(gcmp::IDocument* pDoc, bool isCreating) override;
        virtual bool EndEditing(gcmp::IDocument* pDoc) override;

        ElementId GetReferenceElementId(Int64 projectElementId) const;
        void AddReferenceElement(ElementId referenceElementId, Int64 projectElementId);

        uint16_t GetProjectAppPort() const { return GetProjectAppPort__(); }
        void SetProjectAppPort(uint16_t port) { SetProjectAppPort__(port); }

    public:
        virtual std::wstring GetEditModeType() const override { return InplaceEditModeType; }
        virtual bool IsElementEditable(const gcmp::IElement* pElement) const override;
        virtual bool IsNotAffectedByViewRange(const gcmp::IElement* pElement) const override { return false; }

        virtual void ReportParents(gcmp::IDocument* pDoc, gcmp::IElementParentReporter& reporter) const override;
        virtual void UpdateForWeakParentDeletion(gcmp::IDocument* pDoc, const std::set<gcmp::ElementId>& deletedElementIds) override;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };
}

